package com.situ.day4;

import org.junit.Test;

public class OOPDemo {

    @Test
    public void test1() {
        //Scanner scanner = new Scanner(System.in);
        //student1: 变量、对象（new出来）
        Student student1 = new Student();
        //对象.属性
        student1.id = 1;
        student1.name = "张三";
        student1.age = 23;
        student1.gender = "男";

        Student student2 = new Student();
        //对象.属性
        student2.id = 2;
        student2.name = "李四";
        student2.age = 24;
        student2.gender = "女";

        int[] array = new int[2];
        Student[] students = new Student[2];
        students[0] = student1;
        students[1] = student2;
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            System.out.println(student.id);
            System.out.println(student.name);
            System.out.println(student.age);
            System.out.println(student.gender);
        }
    }

    @Test
    public void test2() {
        Student student = new Student();
        System.out.println(student.id);//0
        System.out.println(student.name);//null
        System.out.println(student.age);//0
        System.out.println(student.gender);//null
        //System.out.println(student.salary);//0.0
        //System.out.println(student.scores);//null

        int[] array1 = new int[3];
        boolean[] array2 = new boolean[3];
        Student[] array3 = new Student[3];
    }

    @Test
    public void test34() {
        //局部变量(局部变量)
        Student student = null;
        //Variable 'student' might not have been initialized
        //局部变量必须要初始化
        System.out.println(student);//null
        //java.lang.NullPointerException
        // null.属性 或者 null.方法
        System.out.println(student.id);
    }

    @Test
    public void test455() {
        Student student = new Student();
        student.id = 1;
        student.name = "张三";
        student.age = 23;
        student.gender = "男";
        System.out.println(student.id);
        System.out.println(student.name);
        System.out.println(student.age);
        System.out.println(student.gender);
        System.out.println("----------");
        //对象.方法()
        String info1 = student.getInfo();
        System.out.println(info1);
        String info2 = student.toString();
        System.out.println(info2);
        System.out.println(student.toString());
        //可以简写成
        System.out.println(student);

    }

    @Test
    public void test234() {
        Student student = new Student();
        student.id = 1;
        student.age = 230;
    }

}
